<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" scope="session"/>
<!DOCTYPE>
<html>
<head>

<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/bootstrap-datetimepicker.js'/>" charset="UTF-8"></script>
<title>任务管理</title>
</head>
<body>
	<div class="col-lg-12">
		<div class="panel panel-default bk-bg-white">
			<div class="panel-body">
				<form class="form-horizontal" id="searchForm">
					<div class="row">
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">任务编号：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="taskId" name="taskId" placeholder="任务编号">
							</div>
						</div>
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">平&nbsp;&nbsp;&nbsp;台：</label>
							<div class="col-sm-8">
								<select id="platformId" name="platformId" class="form-control">
									<option value="">全部</option>
									<option value="1">淘宝/天猫</option>
									<option value="2">京东</option>
								</select>
							</div>
						</div>
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">店铺名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="storename"  name="storename" placeholder="店铺名称">
							</div>
						</div>
					</div>
					<div class="row">
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">终端：</label>
							<div class="col-sm-8">
								<select id="terminalId" name="terminalId" class="form-control">
									<option value="">全部</option>
									<option value="1">PC</option>
									<option value="2">手机</option>
									<option value="3">淘宝 </option>
									<option value="4">天猫</option>
								</select>
							</div>
						</div>
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">任务类型：</label>
							<div class="col-sm-8">
								<select id="taskTypeId" name="taskTypeId" class="form-control">
									<option value="">全部类型</option>
									<option value="1">常规任务</option>
									<option value="2">特色任务</option>
									<option value="3">快速任务 </option>
									<option value="4">特殊任务</option>
								</select>
							</div>
						</div>
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">任务状态：</label>
							<div class="col-sm-8">
								<select id="taskStatus" name="taskStatus" class="form-control">
									<option value="">全部状态</option>
									<option value="1">保存未发布</option>
									<option value="2">已发布</option>
									<option value="3">已撤销 </option>
									<option value="4">进行中</option>
									<option value="5">已完成</option>
								</select>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">商家生财ID：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="businessUserId" name="businessUserId" placeholder="商家生财ID">
							</div>
						</div>
						<div class="form-group col-sm-8">
							<label class="col-sm-2 control-label">发布时间：</label>
							<div class="col-sm-3">
								<input type="text" class="input-append date form_datetime form-control" id="starttime" name="starttime" placeholder="开始时间">
							</div>
							<span style="float: left; padding-top: 10px;">~</span>
							<div class="col-sm-3">
								<input type="text" class="input-append date form_datetime form-control" id="endtime" name="endtime"  placeholder="结束时间">
							</div>
						</div>
					</div>
					<div class="form-group col-sm-12" style="padding-bottom: 15px; text-align: center;">
						<button type="button" id="searchButton" class="btn btn-primary glyphicon glyphicon-search"> 搜索</button>
						<button type="button" id="report" class="btn btn-success glyphicon glyphicon-download"> 批量导出</button>
					</div>
				</form>
				<div class="table-responsive">
					<table class="display nowrap" cellspacing="0" width="100%" id="table">
						<thead>
							<tr>
								<th>任务编号</th>
								<th>任务状态</th>
								<th>商家生财ID</th>
								<th>店铺名称</th>
								<th>平台</th>
								<th>任务类型</th>
								<th>总单数</th>
								<!-- <th>发布时间</th> -->
								<th>操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	
	
	$(function($) {
		//日期控件
 		$('#starttime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii', 
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var starttime = $(this).val();
			$('#endtime').datetimepicker('setStartDate',starttime);
            $(this).datetimepicker('hide');  
        });
		
		$('#endtime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var time = $(this).val();
			$('#starttime').datetimepicker('setEndDate',time);
            $(this).datetimepicker('hide');  
        });
		
		function doSearch(){ 
			//table展示
			var table = $('#table').DataTable( {
		        "processing": true,
		        "serverSide": true,
		        "bLengthChange": false,
		        "bFilter": false,
		        "bSort":false,
		        "bDestroy":true,
		        "language": {
		            "url": path+"/static/language_datatables.json"
		        },
		        "ajax": {
		            "url": path+"/task/taskList",
		            "type": "POST",
		            "data":{
	                	"taskId": $('#taskId').val(),
	                	"platformId": $('#platformId').val(),//审核申请ID
	                    "storename": $('#storename').val(),//审核ID类型
	                    "terminalId": $('#terminalId').val(),//审核申请类型
	                    "taskTypeId": $('#taskTypeId').val(),//审核申请状态
	                    "taskStatus": $('#taskStatus').val(),
	                    "businessUserId": $('#businessUserId').val(),
	                    "starttime": $('#starttime').val(),
	                    "endtime": $('#endtime').val(),
		            }
		        },
		        "columns": [
		            { "data": "taskid","width": "20%"},
		            { "data": "taskstatus","width": "10%" },
		            { "data": "businessuserid","width": "15%" },
		            { "data": "storename" ,"width": "20%"},
		            { "data": "platformid" ,"width": "10%"},
		            { "data": "tasktypeid" ,"width": "10%"},
		            { "data": "totalorders" ,"width": "10%"}, 
		            { "data": "taskid","width": "15%"}
		        ],
		        "columnDefs": [
	                 {
	                     "render": function ( data, type, row ) {
	                         if(data==1){
	                        	 return '保存未发布';
	                         }else if(data==2){
	                        	 return '已发布';
	                         }else if(data==3){
	                        	 return '已撤销';
	                         }else if(data==4){
	                        	 return '进行中';
	                         }else {
	                        	 return '已完成';
	                         }
	                     },
	                     "targets": 1
	                 },
	                {
	                     "render": function ( data, type, row ) {
	                         if(data==1){
	                        	 return '淘宝/天猫';
	                         }else{
	                        	 return '京东';
	                         }
	                     },
	                     "targets": 4
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                         if(data==1){
	                        	 return '常规任务';
	                         }else if(data==2){
	                        	 return '特色任务';
	                         }else if(data==3){
	                        	 return '快速任务';
	                         }else if(data==4){
	                        	 return '特殊任务';
	                         }
	                     },
	                     "targets": 5 
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                         return '<a class="btn btn-warning" href="'+path+'/task/detail/'+data+'?_d='+new Date().getTime()+'">查看任务详情</a>';
	                     },
	                     "targets": 7
	                 } 
	             ]

		    });
		};
		doSearch();
		//查询事件
		$('#searchButton').click(function(){
			doSearch();
		});
		
		//导出
		$('#report').click(function(){
			$('#searchForm').attr("action",path+"/task/reportTask");
			$('#searchForm').submit();
			$('#searchForm').attr("action","");
		});
		
	});
	 
	</script>
</body>
</html>